/*
 * logrw_util.h
 *
 *  Created on: Nov 16, 2011
 *      Author: rui
 */

#ifndef LOGRW_UTIL_H_
#define LOGRW_UTIL_H_

#define ERROR -1
#define SUCCESS 0
#define TRUE 1
#define FALSE 0

typedef struct mutex_t {
	sthread_rwlock_t mutex;
	sthread_mutex_t mutex_count;
	int count; //number of threads locked in mutex
} mutex_t;

void mutex_init(mutex_t *m);
void mutex_destroy(mutex_t *m);
int mutex_rdlock(mutex_t *m);
int mutex_wrlock(mutex_t *m);
int mutex_unlock(mutex_t *m);
int mutex_trylock(mutex_t *m);


void* safeMalloc( size_t size);



typedef struct reg_t {
	int reg;
	int x;
	int y;
	mutex_t mutex;
}reg_t;

void reg_print(reg_t* r);
void reg_init(reg_t *r,int index, int array);
void reg_free(reg_t *r);




#endif /* LOGRW_UTIL_H_ */
